package com.vercon.moensmart.view;

import android.content.Context;
import android.util.AttributeSet;
import android.webkit.WebSettings;
import android.webkit.WebView;

import com.google.gson.Gson;
import com.vercon.common.utils.LogUtils;
import com.vercon.moensmart.MainActivity;

import me.jessyan.autosize.AutoSize;

public class EchartsView extends WebView {
    private static final String TAG = EchartsView.class.getSimpleName();

    public EchartsView(Context context) {
        this(context, null);
    }

    public EchartsView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public EchartsView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public void setOverScrollMode(int mode) {
        super.setOverScrollMode(mode);
        AutoSize.autoConvertDensityOfGlobal(MainActivity.Instance);
    }

    //配置webview，设定加载的url文件路劲
    public void init(String url) {
        WebSettings webSettings = getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        webSettings.setSupportZoom(false);
        webSettings.setDisplayZoomControls(false);
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        loadUrl(url);
    }

    /**刷新图表
     */
     public void refreshEchartsWithOption(Object value) {
         LogUtils.e("","refreshEchartsWithOption " + new Gson().toJson(value));
        String call = "javascript:loadEcharts('" + new Gson().toJson(value)+ "')";
        loadUrl(call);
    }
}